/*******************************************************************************
 * CopyRight (c) 2020 
 *
 * \file    mkv.h
 * \brief   mkv format option
 * \author  ZhangJing
 * \version 1.0.0
 * \date    2020-07-02
 *
 * -----------------------------------------------------------------------------
 *
 * -----------------------------------------------------------------------------
 * Modify History：
 * <Date>       | <Version> | <Author>  | <Discribe>
 * 2020-07-02   | v1.0.0    | ZhangJing | Create file
 * -----------------------------------------------------------------------------
 ******************************************************************************/

#ifndef _MKV__H
#define _MKV__H

#include "publicdef.h"
#include "print_ctrl.h"

/*
 * MKV element IDs, max. 32 bits
 */

/* general EBML types */
#define EBML_ID_VOID               0xEC
#define EBML_ID_CRC32              0xBF
#define EBML_ID_UNKNOWN 0xFFFFFFFF

/* id of MKV ebml */
#define EBML_ID_HEADER  0x1A45DFA3
    /* IDs in the HEADER master */
    #define EBML_ID_EBMLVERSION        0x4286
    #define EBML_ID_EBMLREADVERSION    0x42F7
    #define EBML_ID_EBMLMAXIDLENGTH    0x42F2
    #define EBML_ID_EBMLMAXSIZELENGTH  0x42F3
    #define EBML_ID_DOCTYPE            0x4282
    #define EBML_ID_DOCTYPEVERSION     0x4287
    #define EBML_ID_DOCTYPEREADVERSION 0x4285
/* toplevel segment */
#define MKV_ID_SEGMENT    0x18538067
    /* MKV top-level master IDs */
    #define MKV_ID_SEEKHEAD   0x114D9B74
        /* IDs in the seekhead master */
        #define MKV_ID_SEEKENTRY  0x4DBB
            /* IDs in the seekpoint master */
            #define MKV_ID_SEEKID     0x53AB
            #define MKV_ID_SEEKPOSITION 0x53AC
    #define MKV_ID_INFO       0x1549A966
        /* IDs in the info master */
        #define MKV_ID_TIMECODESCALE 0x2AD7B1
        #define MKV_ID_DURATION   0x4489
        //#define MKV_ID_TITLE      0x7BA9
        #define MKV_ID_WRITINGAPP 0x5741
        #define MKV_ID_MUXINGAPP  0x4D80
        #define MKV_ID_DATEUTC    0x4461
        #define MKV_ID_SEGMENTUID 0x73A4
    #define MKV_ID_TRACKS     0x1654AE6B
        /* ID in the tracks master */
        #define MKV_ID_TRACKENTRY 0xAE
            /* IDs in the trackentry master */
            #define MKV_ID_TRACKNUMBER 0xD7
            #define MKV_ID_TRACKUID   0x73C5
            #define MKV_ID_TRACKTYPE  0x83
            #define MKV_ID_TRACKVIDEO     0xE0
                /* IDs in the trackvideo master */
                //#define MKV_ID_VIDEOFRAMERATE 0x2383E3
                #define MKV_ID_VIDEODISPLAYWIDTH 0x54B0
                #define MKV_ID_VIDEODISPLAYHEIGHT 0x54BA
                #define MKV_ID_VIDEOPIXELWIDTH 0xB0
                #define MKV_ID_VIDEOPIXELHEIGHT 0xBA
                //#define MKV_ID_VIDEOPIXELCROPB 0x54AA
                //#define MKV_ID_VIDEOPIXELCROPT 0x54BB
                //#define MKV_ID_VIDEOPIXELCROPL 0x54CC
                //#define MKV_ID_VIDEOPIXELCROPR 0x54DD
                //#define MKV_ID_VIDEODISPLAYUNIT 0x54B2
                #define MKV_ID_VIDEOFLAGINTERLACED 0x9A
                //#define MKV_ID_VIDEOFIELDORDER 0x9D
                //#define MKV_ID_VIDEOSTEREOMODE 0x53B8
                //#define MKV_ID_VIDEOALPHAMODE 0x53C0
                //#define MKV_ID_VIDEOASPECTRATIO 0x54B3
                //#define MKV_ID_VIDEOCOLORSPACE 0x2EB524
                //#define MKV_ID_VIDEOCOLOR 0x55B0
            #define MKV_ID_TRACKAUDIO     0xE1
                /* IDs in the trackaudio master */
                #define MKV_ID_AUDIOSAMPLINGFREQ 0xB5
                //#define MKV_ID_AUDIOOUTSAMPLINGFREQ 0x78B5
                #define MKV_ID_AUDIOBITDEPTH 0x6264
                #define MKV_ID_AUDIOCHANNELS 0x9F
            //#define MKV_ID_TRACKOPERATION 0xE2
            //#define MKV_ID_TRACKCOMBINEPLANES 0xE3
            //#define MKV_ID_TRACKPLANE         0xE4
            //#define MKV_ID_TRACKPLANEUID      0xE5
            //#define MKV_ID_TRACKPLANETYPE     0xE6
            #define MKV_ID_CODECID    0x86
            #define MKV_ID_CODECPRIVATE 0x63A2
            //#define MKV_ID_CODECNAME  0x258688
            //#define MKV_ID_CODECINFOURL 0x3B4040
            //#define MKV_ID_CODECDOWNLOADURL 0x26B240
            //#define MKV_ID_CODECDECODEALL 0xAA
            //#define MKV_ID_CODECDELAY 0x56AA
            //#define MKV_ID_SEEKPREROLL 0x56BB
            //#define MKV_ID_TRACKNAME  0x536E
            #define MKV_ID_TRACKLANGUAGE 0x22B59C
            //#define MKV_ID_TRACKFLAGENABLED 0xB9
            //#define MKV_ID_TRACKFLAGDEFAULT 0x88
            //#define MKV_ID_TRACKFLAGFORCED 0x55AA
            #define MKV_ID_TRACKFLAGLACING 0x9C
            #define MKV_ID_TRACKMINCACHE 0x6DE7
            //#define MKV_ID_TRACKMAXCACHE 0x6DF8
            #define MKV_ID_TRACKDEFAULTDURATION 0x23E383
            //#define MKV_ID_TRACKCONTENTENCODINGS 0x6D80
            //#define MKV_ID_TRACKCONTENTENCODING 0x6240
            //#define MKV_ID_TRACKTIMECODESCALE 0x23314F
            //#define MKV_ID_TRACKMAXBLKADDID 0x55EE
    #define MKV_ID_CUES       0x1C53BB6B
        /* ID in the cues master */
        #define MKV_ID_POINTENTRY 0xBB
            /* IDs in the pointentry master */
            #define MKV_ID_CUETIME    0xB3
            #define MKV_ID_CUETRACKPOSITION 0xB7
                /* IDs in the cuetrackposition master */
                #define MKV_ID_CUETRACK   0xF7
                #define MKV_ID_CUECLUSTERPOSITION 0xF1
                #define MKV_ID_CUERELATIVEPOSITION 0xF0
                //#define MKV_ID_CUEDURATION 0xB2
                //#define MKV_ID_CUEBLOCKNUMBER 0x5378
    #define MKV_ID_TAGS       0x1254C367
        /* IDs in the tags master */
        #define MKV_ID_TAG                 0x7373
            #define MKV_ID_TAGTARGETS          0x63C0
        #define MKV_ID_SIMPLETAG           0x67C8
            #define MKV_ID_TAGNAME             0x45A3
            #define MKV_ID_TAGSTRING           0x4487
    #define MKV_ID_CLUSTER    0x1F43B675
        /* IDs in the cluster master */
        #define MKV_ID_CLUSTERTIMECODE 0xE7
        //#define MKV_ID_CLUSTERPOSITION 0xA7
        //#define MKV_ID_CLUSTERPREVSIZE 0xAB
        //#define MKV_ID_BLOCKGROUP 0xA0
        //#define MKV_ID_BLOCKADDITIONS 0x75A1
        //#define MKV_ID_BLOCKMORE 0xA6
        //#define MKV_ID_BLOCKADDID 0xEE
        //#define MKV_ID_BLOCKADDITIONAL 0xA5
        #define MKV_ID_SIMPLEBLOCK 0xA3
    //#define MKV_ID_ATTACHMENTS 0x1941A469
    //#define MKV_ID_CHAPTERS   0x1043A770

/* -----------------the id struction--------------- */
//EBML
    //EBML_Version
    //EBML_ReadVersion
    //EBML_MaxIDLength
    //EBML_MaxSizeLength
    //DocType
    //DocTypeVersion
    //DOcTypeReadVersion
//SEGMENT
    //SEEKHEAD
        //CRC
        //Seek
            //SeekID
            //SeeKPosition
    //Void
    //SEGMENTINFO
        //TimeCodeScale
        //MuxingApp
        //WritingApp
        //DateUTC
        //SegmentUID
        //Duration
    //TRACKS
        //TrackEntry
            //TrackNumber
            //TrackUID
            //FlagLacing
            //MinCache
            //Language
            //CodecID
            //TrackType
            //DefaultDuration
            //Video
                //PixelWidth
                //PixelHeight
                //FlagInterlaced
                //DisplayWidth
                //DisplayHeight
            //CodePrivate
            //Audio
                //Channels
                //SamplingFrequency
                //BitDepth
    //TAGS
        //Tag
            //Targets
            //SimpleTag
                //TagName
                //TagString
    //CLUSTER
        //TimeCode
        //SimpleBlock
    //CUES
        //CuePoint
            //CueTime
            //CueTrackPositions
                //CueClusterPosition
//UNKNOWN 0xFFFFFFFF

typedef enum EbmlType {
    EBML_NONE,
    EBML_BIN,
    EBML_STRING,
    EBML_NEST,
    EBML_SKIP,
    EBML_STOP
} EbmlType;

typedef struct MkvSyntax {
    unsigned int id;
    char *name;
    EbmlType type;
    unsigned long size;
    unsigned long offset;
    int (*parser)(void *, struct MkvSyntax *);
} MkvSyntax;

typedef struct MkvStream {
    int pps_data_len;
    unsigned char *pps_data; /**< pps data in box embl CodecProvate(cmd 0x63a2) */
} MkvStream;

#endif /* _MKV__H */
